import "package:flutter/material.dart";
import "package:myapp/_common/NestedTabBarView.dart";

import "widget/movie/MovieMenu.dart"; //方块按钮标签
import "widget/movie/MovieCardList.dart"; //影视卡片列表
import "widget/movie/movieTitleBar.dart"; //影视模块的标题栏

import "widget/movie/MovieSwiper.dart"; //轮播图
import "widget/movie/MovieSeries.dart"; //影视系列
import "widget/movie/movieRank.dart"; //影视排行榜
import "widget/movie/MovieOfficialRecommend.dart"; //影视官方推荐
import "widget/movie/MovieLike.dart"; //影视猜你喜欢

final List<MovieCard> watchingMovieList = [
  MovieCard(
    title: "工作细胞：细胞大作战",
    subTitle: "看到原版54%",
    cover: "images/1.jpg",
    progress: 54,
  ),
  MovieCard(
    title: "2023最美的夜 bilibili晚会",
    subTitle: "跨年音乐现场狂欢",
    cover: "images/2.jpg",
  ),
  MovieCard(
    title: "非正式会谈 第8季",
    subTitle: "分享各国趣闻",
    cover: "images/3.jpg",
  ),
  MovieCard(
    title: "新世纪福音战士新剧场版：终",
    subTitle: "再见了所有的EVA",
    cover: "images/4.jpg",
  ),
  MovieCard(
    title: "紫罗兰的永恒花园 剧场版",
    subTitle: "京都动画催泪之作",
    cover: "images/5.jpg",
  ),
  MovieCard(
    title: "2021最美的夜 bilibili晚会",
    subTitle: "送你一场焰火",
    cover: "images/6.jpg",
  ),
  MovieCard(
    title: "非正式会谈 第6.5季",
    subTitle: "看到第四期未播片段 8%",
    cover: "images/7.jpg",
    progress: 8,
    episodes: 10,
    showEpisodes: true,
  ),
];

final List<MovieCard> movieSeriesList = [
  MovieCard(
    title: "星球大战：绝地归来",
    cover: "images/1.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战：帝国反击战",
    cover: "images/2.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战外传：侠盗一号",
    cover: "images/3.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战：原力觉醒",
    cover: "images/4.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战：最后的绝地武士",
    cover: "images/5.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战：天行者崛起",
    cover: "images/6.jpg",
    subTitle: "",
  ),
  MovieCard(
    title: "星球大战：侠盗一号",
    cover: "images/7.jpg",
    subTitle: "",
  ),
];

List<MovieLikeItem> movieLikeList = [
  MovieLikeItem(
    type: MovieLikeType.separate,
    title: '2019最美的夜 bilibili晚会',
    cover: 'images/1.jpg',
    partition: '综艺',
    style: '晚会',
    honor: '中国电视金鹰奖题名',
    barColor: const Color(0xff132835),
  ),
  MovieLikeItem(
    type: MovieLikeType.separate,
    title: 'Doctor X 第六季',
    cover: 'images/2.jpg',
    partition: '电视剧',
    style: '悬疑',
    description: '王炸外科医回归',
    barColor: const Color(0xff342713),
  ),
  MovieLikeItem(
    type: MovieLikeType.collection,
    title: 'B站高能短句集安利',
    cover: 'images/3.jpg',
    subTitle: '片单推荐',
    cardList: [
      MovieCard(
        title: "抓马侦探2",
        cover: "images/1.jpg",
        subTitle: "脑洞反转不停歇！",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "片场日记2",
        cover: "images/2.jpg",
        subTitle: "高分爆更喜剧续作",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "冯宝宝与张楚岚",
        cover: "images/3.jpg",
        subTitle: "《一人之下》漫改剧",
        episodes: 30,
        showEpisodes: true,
      ),
      MovieCard(
        title: "抓马侦探2",
        cover: "images/1.jpg",
        subTitle: "脑洞反转不停歇！",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "片场日记2",
        cover: "images/2.jpg",
        subTitle: "高分爆更喜剧续作",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "冯宝宝与张楚岚",
        cover: "images/3.jpg",
        subTitle: "《一人之下》漫改剧",
        episodes: 30,
        showEpisodes: true,
      ),
    ],
    backgroundColor: const Color(0xff2d343e),
  ),
  MovieLikeItem(
    type: MovieLikeType.separate,
    title: '秘密特工',
    cover: 'images/4.jpg',
    partition: '电影',
    style: '喜剧',
    description: '盖里奇式燃爆谍战',
    barColor: const Color(0xff352113),
  ),
  MovieLikeItem(
    type: MovieLikeType.separate,
    title: '抓娃娃',
    cover: 'images/5.jpg',
    partition: '电影',
    style: '喜剧',
    description: '沈马组合爆笑养娃',
    barColor: const Color(0xff342511),
  ),
  MovieLikeItem(
    type: MovieLikeType.separate,
    title: '贝爷绝世大冒险',
    cover: 'images/6.jpg',
    partition: '纪录片',
    style: '探险',
    description: '有深度的生存节目',
    barColor: const Color(0xff122634),
  ),
  MovieLikeItem(
    type: MovieLikeType.collection,
    title: '热门影视榜',
    cover: 'images/7.jpg',
    subTitle: '每小时更新',
    cardList: [
      MovieCard(
        title: "守护解放西5",
        cover: "images/1.jpg",
        subTitle: "脑洞反转不停歇！",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "闪闪的儿科医生2",
        cover: "images/2.jpg",
        subTitle: "高分爆更喜剧续作",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "你想活出怎样的人生",
        cover: "images/3.jpg",
        subTitle: "宫崎骏御用作曲家久石让配乐",
        episodes: 30,
        showEpisodes: true,
      ),
      MovieCard(
        title: "我叫赵甲第",
        cover: "images/1.jpg",
        subTitle: "《剑来》改编",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "片场日记2",
        cover: "images/2.jpg",
        subTitle: "高分爆更喜剧续作",
        episodes: 12,
        showEpisodes: true,
      ),
      MovieCard(
        title: "冯宝宝与张楚岚",
        cover: "images/3.jpg",
        subTitle: "《一人之下》漫改剧",
        episodes: 30,
        showEpisodes: true,
      ),
    ],
    backgroundColor: const Color(0xff2d343e),
  ),
];

TextStyle leadingTitleTextStyle = const TextStyle(
  fontSize: 16,
  color: Color(0xff1c1c1c),
  fontWeight: FontWeight.bold,
);
TextStyle trailingTitleTextStyle = const TextStyle(
  fontSize: 13,
  color: Color(0xff94969a),
);
Icon trailingIcon = const Icon(
  Icons.arrow_forward_ios,
  size: 16,
  color: Color(0xff94969a),
);

class MovieWidget extends StatelessWidget {
  const MovieWidget({super.key});
  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      controller: NestedInnerScrollController.maybeOf(context),
      slivers: [
        // 处理嵌套遮挡问题
        SliverOverlapInjector(
          handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
        ),
        SliverToBoxAdapter(
          child: MovieSwipert(),
        ),
        MovieMenu(),
        const SliverToBoxAdapter(
          child: MovieTitleBar(
            leadingTitle: '正在追',
            trailingTitle: '我的追剧',
          ),
        ),
        SliverToBoxAdapter(
          child: Container(
            color: const Color(0xfffffffd),
            child: MovieCardList(
              cardList: watchingMovieList,
              size: CardSize.small,
            ),
          ),
        ),
        const SliverToBoxAdapter(
          child: MovieTitleBar(
            leadingTitle: '正在热播',
          ),
        ),
        SliverToBoxAdapter(
          child: Container(
            color: const Color(0xfffffffd),
            child: MovieCardList(
              cardList: watchingMovieList,
              size: CardSize.large,
            ),
          ),
        ),
        const SliverToBoxAdapter(
          child: MovieTitleBar(
            leadingTitle: '热门排行榜',
            trailingTitle: '更多榜单',
          ),
        ),
        SliverToBoxAdapter(
          child: MovieRank(cardList: watchingMovieList),
        ),
        SliverToBoxAdapter(
          child: Container(
            color: const Color(0xfffffffd),
            padding: const EdgeInsets.symmetric(vertical: 8),
            child: AspectRatio(
              aspectRatio: 6 / 5,
              child: SizedBox(
                width: double.infinity,
                child: MovieSeries(
                  items: movieSeriesList,
                  seriesTitle: '星球大战家族恩怨史',
                  seriesCover: 'images/1.jpg',
                  linearGradientColor: const Color(0xff2d343e),
                ),
              ),
            ),
          ),
        ),
        SliverToBoxAdapter(
          child: MovieOfficialRecommendWrap(itemList: [
            MovieOfficialRecommendItem(
              title: '冬季鉴赏指南，天冷加衣哦~',
              user: OfficialUser(
                avatar: 'images/tab_1.jpg',
                name: '哔哩哔哩纪录片',
              ),
              cardList: watchingMovieList,
            ),
            MovieOfficialRecommendItem(
              title: '头好痒，感觉要长脑子了！',
              user: OfficialUser(
                avatar: 'images/tab_2.jpg',
                name: '综艺哔哔机',
              ),
              cardList: watchingMovieList,
            ),
            MovieOfficialRecommendItem(
              title: '越看越饿，B站“下饭”好剧',
              user: OfficialUser(
                avatar: 'images/tab_3.jpg',
                name: '迷影社',
              ),
              cardList: watchingMovieList,
            ),
          ]),
        ),
        const SliverToBoxAdapter(
          child: MovieTitleBar(
            leadingTitle: '猜你喜欢',
          ),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) => MovieLikeCardItem(item: movieLikeList[index]),
            childCount: movieLikeList.length,
          ),
        ),
        const SliverToBoxAdapter(
          child: SizedBox(height: 200),
        ),
      ],
    );
  }
}
